import { userManage } from '@/lib/user-manage'
import { userLoginVerify } from '@/lib/validation'
import { Component, Vue } from 'vue-property-decorator'

@Component
export default class extends Vue {
  // ++++++++++ model ++++++++++
  // ++++++++++ props ++++++++++
  // ++++++++++ data ++++++++++
  form = {
    username: '1008611',
    password: '123456',
    type: 'user',
  }

  rules = userLoginVerify()

  // ++++++++++ computed ++++++++++
  // ++++++++++ methods normal ++++++++++
  // ++++++++++ methods event ++++++++++
  submit() {
    const formref = this.$refs.form as any

    formref.validate(async (valid: boolean) => {
      if (valid) {
        const userinfo = await this.$Api.user.login(this.form)

        userManage.setUserInfoAndToken(userinfo)
        userManage.handleLogin(this, userinfo)
        this.$message.success("登录成功")
      }
    })
  }
  // ++++++++++ Lifecycle Hooks ++++++++++
  // ++++++++++ watch ++++++++++
}
